from selenium import webdriver
from selenium.webdriver.common.by import By
import time


class TestCase:
    def __init__(self):
        self.driver = webdriver.Chrome()

    # 首页搜索 资生堂
    def search(self):
        # 打开ecshop首页
        self.driver.get('https://ecshop.test2.shopex123.com/')
        # 定位搜索框，并输入关键字‘资生堂’
        self.driver.find_element(By.ID, 'keyword').send_keys('资生堂')
        # 定位搜索按钮，并点击
        self.driver.find_element(By.CLASS_NAME, 'btn_search').click()

    # 注册
    def register(self):
        # 打开注册页面
        self.driver.get('https://ecshop.test2.shopex123.com/user.php?act=register')
        # 定位用户名框，输入用户名
        self.driver.find_element(By.ID, 'username').send_keys('gulala')
        # 定位邮箱框，输入邮箱
        self.driver.find_element(By.ID, 'email').send_keys('123@htm.com')
        # 定位密码框，输入密码
        self.driver.find_element(By.ID, 'password1').send_keys('gulala123')
        # 定位确认密码框，确认密码
        self.driver.find_element(By.ID, 'confirm_password').send_keys('gulala123')
        time.sleep(2)
        # 点击登录按钮
        self.driver.find_element(By.NAME, 'Submit').click()

    # 登录
    def login(self):
        # 打开登录页面
        self.driver.get('https://ecshop.test2.shopex123.com/user.php')
        # 定位用户名框，并输入用户名
        self.driver.find_element(By.NAME, 'username').send_keys('gulala')
        # 定位密码框，并输入密码
        self.driver.find_element(By.NAME, 'password').send_keys('gulala123')
        # 定位登录按钮，并点击
        time.sleep(2)
        self.driver.find_element(By.NAME, 'submit').click()

    def quit(self):
        time.sleep(2)
        self.driver.quit()


if __name__ == '__main__':
    b = TestCase()
    # b.search()
    # b.register()
    b.login()
    b.quit()
